import { createWebHistory, createRouter } from 'vue-router'
import Layout from '@/layout'

// 公共路由
export const constantRoutes = [
  {
    path: '',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: () => import('@/views/index'),
        name: 'Index',
        meta: { title: '首页', affix: true }
      },
      {
        path: '/wind-farm',
        component: () => import('@/views/wind-farm'),
        name: 'WindFarm',
        meta: { title: '风电场', affix: true }
      },
      {
        path: '/dispatch',
        component: () => import('@/views/dispatch'),
        name: 'Dispatch',
        meta: { title: '送端换流站', affix: true }
      },
      {
        path: '/receive',
        component: () => import('@/views/receive'),
        name: 'Receive',
        meta: { title: '受端换流站', affix: true }
      },
      {
        path: '/burden',
        component: () => import('@/views/burden'),
        name: 'Burden',
        meta: { title: '负荷', affix: true }
      },
      {
        path: '/data-view',
        component: () => import('@/views/data-view'),
        name: 'DataView',
        meta: { title: '数据查看', affix: true }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router
